import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: '/',
        component: () => import('@/views/login')
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login')
    },
    {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home')
    },
    {
        path: '/checkAndUpdate',
        name: 'checkAndUpdate',
        component: () => import('@/views/checkAndUpdate')
    },
    {
        path: '/capture',
        name: 'capture',
        component: () => import('@/views/capture')
    }
]

const router = new VueRouter({
    mode: 'hash',
    routes
})

router.beforeEach((to, from, next) => {
    document.title = window.platform.title
    var authorization = localStorage.getItem('Authorization')
    if (authorization) {
        next()
    } else {
        if (to.path === '/' || to.path === '/checkAndUpdate' || to.path === '/capture') {
            next()
        } else {
            next('/')
        }
    }
})

export default router
